package com.zxmr.domain.service;

import java.sql.SQLException;
import java.util.List;

import com.zxmr.CommonInit;
import com.zxmr.db.DBManager;
import com.zxmr.domain.Host;

public class HostService {

	DBManager db = CommonInit.getDBManager();
	
	public boolean addHost(Host host)
	{
		try
		{
			db.getMapper().insert("host.add",host);
			return true;
		}catch(SQLException e)
		{
			e.printStackTrace();
		}
		
		return false;
	}
	@SuppressWarnings("unchecked")
	public List<Host> queryHosts()
	{
		try
		{
			return (List<Host>)db.getMapper().queryForList("host.find");
		}catch(SQLException e)
		{
			e.printStackTrace();
		}
		return null;
	}
	
	public boolean updateHost(Host host)
	{
		try
		{
			db.getMapper().update("host.update", host);
			return true;
		}catch(SQLException e)
		{
			e.printStackTrace();
		}
		return false;
	}
	public void deleteHost(String host)
	{
		try
		{
			db.getMapper().delete("host.delete", host);
		}catch(SQLException e)
		{
			e.printStackTrace();
		}
	}
	
	public Host queryByName(String name)
	{
		try
		{
			return (Host)db.getMapper().queryForObject("findByName", name);
		}catch(SQLException e)
		{
			e.printStackTrace();
		}
		return null;
	}
}
